#include "msgbuffer.h"

MsgBuffer::MsgBuffer()
{
}


void MsgBuffer::addBytes(Data& bytes)
{
    m_buff.insert(m_buff.end(), bytes.begin(), bytes.end());
}
Message MsgBuffer::getNextMessage()
{
    Message retval = m_parser.parse(Data(m_buff.begin(), m_buff.end()));
    eraseFirstBytes(retval.getMsgBytes().size());
    return retval;
}
void MsgBuffer::eraseFirstBytes(unsigned int num)
{
    std::list<DataType>::iterator it = m_buff.begin();
    for(int i=0;i<num;++i)
        it++;
    if(num <= m_buff.size())
        m_buff = std::list<DataType>(it, m_buff.end());
    else
        throw "you are trying to eraze more than there is in list";
}

bool MsgBuffer::isNextMessageInBuff()
{
    return m_parser.isValidMessageAvaliable(Data(m_buff.begin(), m_buff.end()));
}
